#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <queue>
#include <cstdio>
#include <string>
#include <stack>
#include <set>
#define IOS ios::sync_with_stdio(false), cin.tie(0)
using namespace std;
typedef long long ll;
ll m,n;
string s[25];
struct node{
    ll x,y,step;
};
ll next_s[4][2]={1,0,-1,0,0,1,0,-1};
queue<node >q;
bool vis[25][25];
int main()
{
    IOS;
    cin>>m>>n;
    memset(vis,false,sizeof(vis));
    ll x0,y0,x1,y1;
    for(ll i=0;i<m;i++){
        cin>>s[i];
    }    
    for(ll i=0;i<m;i++){
        for(ll j=0;j<n;j++){
            if(s[i][j]=='@'){
                x0=i;y0=j;
            }
            if(s[i][j]=='*'){
                x1=i;y1=j;
            }
        }
    }
    node t;
    t.x=x0;
    t.y=y0;
    t.step=0;
    vis[x0][y0]=true;
    q.push(t);
    while(!q.empty()){
        node tmp=q.front();
        if(tmp.x==x1&&tmp.y==y1){
            cout<<tmp.step<<endl;
            break;
        }
        q.pop();
        for(ll i=0;i<4;i++){
            ll tx=tmp.x+next_s[i][0];
            ll ty=tmp.y+next_s[i][1];
            if(tx<0||tx>=m||ty<0||ty>=n||vis[tx][ty]||s[tx][ty]=='#')continue;
            vis[tx][ty]=true;
            t.x=tx;t.y=ty;
            t.step=tmp.step+1;
            q.push(t);
        }
    }
    if(q.empty()){
        cout<<-1<<endl;
    }
    getchar();
    getchar();
    return 0;
}
